﻿using System;
using Newtonsoft.Json;
using OrkutAPILibrary.Enums;

namespace OrkutAPILibrary.Entities
{
    /// <summary>
    /// Base class for all Orkut Activities
    /// </summary>
    public class OrkutActivity
    {
        /// <summary>
        /// Gets or sets the relevant user ids.
        /// </summary>
        /// <value>The relevant user ids.</value>
        [JsonProperty(PropertyName = "relevantUserIds")]
        public string[] RelevantUserIds { get; internal set; }

        /// <summary>
        /// Gets or sets the activity id.
        /// </summary>
        /// <value>The activity id.</value>
        [JsonProperty(PropertyName = "id")]
        public string ActivityId { get; internal set; }

        /// <summary>
        /// Gets or sets the user id.
        /// </summary>
        /// <value>The user id.</value>
        [JsonProperty(PropertyName = "userIds")]
        public string UserId { get; internal set; }

        /// <summary>
        /// Gets or sets the posted time.
        /// </summary>
        /// <value>The posted time.</value>
        public DateTime PostedTime { get; set; }

        internal static readonly DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

        [JsonProperty(PropertyName = "postedTime")]
        internal string _postedTime
        {
            get
            {
                return (PostedTime - unixEpoch).TotalSeconds.ToString();
            }
            set
            {
                PostedTime = unixEpoch.AddSeconds(Convert.ToInt32(value));
            }
        }

        /// <summary>
        /// Gets or sets the activity parameters.
        /// </summary>
        /// <value>The activity parameters.</value>
        [JsonProperty(PropertyName = "templateParams")]
        public ActivityDetails ActivityParameters { get; set; }

        /// <summary>
        /// Gets the Activity type.
        /// </summary>
        public virtual ActivityType GetActivityType()
        {
            throw new NotImplementedException();
        }
    }

    /// <summary>
    /// Activity Details
    /// </summary>
    public class ActivityDetails
    {
        /// <summary>
        /// Gets or sets the album title.
        /// </summary>
        /// <value>The album title.</value>
        [JsonProperty(PropertyName = "albumTitle")]
        public string AlbumTitle { get; internal set; }

        /// <summary>
        /// Gets or sets the album id.
        /// </summary>
        /// <value>The album id.</value>
        [JsonProperty(PropertyName = "albumId")]
        public string AlbumId { get; internal set; }

        /// <summary>
        /// Gets or sets the type.
        /// </summary>
        /// <value>The type.</value>
        [JsonProperty(PropertyName = "activityType")]
        public string Type { get; set; }
    }
}
